home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
program
/
oxcc1434.zip
/
SRC
/
SKELETON.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-06
|
54KB
|
2,319 lines
/* SKELETON.C -- THE PROTOTYPE APPLICATION FOR THE OXBOW FRAMEWORK
COMPILE WITH GCC
COPYRIGHT 1994 Norman D. Culver, Ft. Lauderdale, FL
NOTE: 'main()' is at the end of the file.
*/
#define SYMLINK(from,to) badsyms += oxlink_symlink(#from,#to)
#define EARLY_PRINT 1 /* set to 1 if trace before linkup needed */
#define BASE_CATEGORY 0
#define MEMORY_BUG 0
#define PRINT_RAWDATA 0
#if 0
#define DPRINTF lprintf
#else
#define DPRINTF(args...)
#endif
#if 0
#define MPRINTF lprintf
#else
#define MPRINTF(args...)
#endif
#if EARLY_PRINT == 1
#define TPRINTF lprintf
#else
#define TPRINTF VPRINTF
#endif
#include <go32.h>
/* extracts from 'oxbow.h' */
typedef unsigned long long KeyItem; /* type for a key's associated item */
typedef union /* 2 BYTES */
{
unsigned short val;
unsigned char b[2];
} SVAL;
typedef union /* 4 BYTES */
{
unsigned long a0;
void *a1;
struct
{
SVAL lo_word;
SVAL hi_word;
} a2;
struct
{
unsigned int pad :28;
unsigned int type :4;
} a3;
struct
{
unsigned char b[4];
} a4;
int a8;
short a9;
char a10;
float a11;
} ADDR;
typedef union _stor /* 8 BYTES */
{
unsigned long a0;
void *a1;
KeyItem item;
struct
{
unsigned short lo_word;
unsigned short hi_word;
unsigned int size :28; /* in bytes or nibbles */
unsigned int type :4; /* describes the STOR type */
} a2;
struct
{
short s0;
short s1;
short s2;
short s3;
} a3;
struct
{
unsigned long s0;
unsigned long s1;
} a4;
struct
{
unsigned char b[8];
} a5;
struct
{
unsigned long long dupname :48;
unsigned long long dupid :16;
} a6;
struct
{
unsigned int home : 30;
unsigned int full : 2;
} a7;
int a8;
short a9;
char a10;
float a11;
double a12;
} STOR, Item;
typedef struct /* 12 BYTES */
{
STOR c0;
ADDR c1;
} CAT;
#define OB_XFILE (0x00004000)
#define OB_ROOTDIR (0x00000200)
#define OB_TREEDIR (0x10000000)
#define OB_HASHDIR (0x20000000)
#define F_RDONLY (0x0001)
#define F_STAT (0x20000) /* TRULY READONLY */
#define O_RDONLY (0x0001)
#define O_BINARY (0x8000)
#define R_CLEAN (0x40000000)
#undef NULL
#define NULL ((void *)0)
#define FOUND (1)
#define NODUPS (0)
#define S_SET (0)
#define S_READBLK (1)
#define S_WRITEBLK (2)
#define _cat2_(a, b) a##b
#define _cat_(a, b) _cat2_(a, b)
#define _qt2_(x) #x
#define _qt_(x) _qt2_(x)
#define oxfunc(func, args...) ({ \
typedef _fret = (appfunc()); \
_fret (*dofunc)(); _fret _ret; \
dofunc = oxlink_load_bare_symb(func,1); \
if(dofunc) _ret = dofunc(## args) & 0x0fffffff; \
else _ret = (_fret) -1; \
_ret;})
#define oxload(func) \
oxlink_load_bare_symb(_qt_(_cat_(_, func)),1)
#define oxunload(func) \
oxlink_unload_symb(#func, 1)
typedef int jmp_buf[32]; /* an adequate buffer for setjmp */
int setjmp();
void longjmp();
/* end: extracts from 'oxbow.h' */
/* ==================== A LIST OF PROBLEMS ======================= */
/* external function prototypes needed initially,
THESE NEED TO BE LOCALIZED */
void *sbrk();
int open();
int creat();
int close();
int read();
int write();
int lseek();
char *getenv();
char *getwd();
int strlen();
char *strdup();
char *strcat();
char *strcpy();
char *strchr();
char *strrchr();
char *strstr();
int _strcpy();
long strtol();
int strcmp(const char *, const char *);
int strncmp();
void CF_Interactive_IO();
int appfunc();
void *malloc(unsigned);
void *calloc(unsigned, unsigned);
void free(void*);
void *memcpy();
/* external function prototypes needed by the portability modules
THESE TOO NEED TO BE LOCALIZED (or something) */
void exit();
int ftruncate();
void abort();
/* internal function prototypes */
static int lnulfunc();
static void lhash(void *, int, CAT *);
static int laccess(char *, int);
static int lpagesize(void);
static int lprintchar(int);
static void lprintstr(char *);
static void lcrash(char *, ...);
void CF_InitIO(long arg, long long (*msgproc)());
/* ======================== END LIST OF PROBLEMS ==================== */
/* DYNAMIC LINKER FUNCTIONS */
int oxlink_init (); /* initialize the routines */
int oxlink_load_file (); /* dynamically link and load an object file */
int oxlink_load_object (); /* link object file from libraries in list */
void *oxlink_find_func (); /* return the address of the named function */
void *oxlink_find_bare_func ();/* same as oxlink_find_func except that
no underscore (_) is prepended (also faster). */
void * oxlink_find_sym (); /* return the address of the named identifier */
void *oxlink_find_bare_symb ();/* same as oxlink_find_symb except that
no underscore (_) is prepended (also faster). */
int oxlink_unload_file (); /* unlink a file */
int oxlink_unload_symb (); /* unlink the module that defines the given symbol */
int oxlink_unload_bare_symb (); /* unlink the module that defines the given symbol */
char **oxlink_list_undefined_symb ();/* return an array of undefined symbols */
char *cf_find_file ();/* return the full path name of the given file. */
void *oxlink_load_symb(char *symb, int dynlink);
void *oxlink_load_bare_symb(char *symb, int dynlink);
int oxlink_export_symb();
int oxlink_export_bare_symb();
void oxlink_unexport_symb();
void oxlink_unexport_bare_symb();
int oxlink_symlink(); /* give new symbol same values as old symbol */
void oxlink_demand_load(); /* define all undefined symbols with negative numbers */
void oxlink_use_library(); /* add a filename for undefined symbol search */
void oxlink_nouse_library(); /* remove a library from the search list */
void *oxlink_resolve_symb(); /* resolve one of the demand loadable undefs */
void oxlink_trace(); /* set the trace level */
char *oxlink_symname(); /* return name of a demand loadable undef */
void *oxlink_rename_symb(char *old,char *new);
int oxlink_rename_file(char *old,char *new);
void oxlink_lib_check(int dynlink); /* force search of library list */
char *oxlink_file_of(char *symb);
char *oxlink_file_of_bare(char *symb);
int oxlink_scan_file(void *fhandle, void *thandle);
void oxlink_set_libtype(int type);
void oxlink_set_libnum(int libnum);
void oxlink_load_thunk(int thunknum);
int oxlink_prep_thunk(char *symb);
void oxlink_clear_bss(char *filename);
void *oxlink_get_entry_struct(char *filename);
char *oxlink_errstr(void);
/* virtual function pointers initially hard linked to the load module */
/* needed in order to initialize and read a .o or .a file */
int (*VCFREAD)() = read;
int (*VCFWRITE)() = write;
void *(*VCFOPEN)() = (void *)open;
int (*VCFCLOSE)() = close;
int (*VCFLSEEK)() = lseek;
int (*VACCESS)() = laccess;
void *(*VSBRK)() = sbrk;
char *(*VGETENV)() = getenv;
char *(*VGETCWD)() = getwd;
int (*VOBTYPE)() = lnulfunc;
void (*VHASH)() = lhash;
int (*VGETPAGESIZE)() = lpagesize;
#if EARLY_PRINT == 0
int (*VVPRINTF)() = lnulfunc;
int (*VSPRINTF)() = lnulfunc;
int (*VPRINTF)() = lnulfunc;
int (*BUGPRINTF)() = lnulfunc;
#else
static int lvprintf(char *, void *);
static int lsprintf(char *, char *, ...);
static int lprintf(char *, ...);
int (*VVPRINTF)(char *, void*) = lvprintf;
int (*VSPRINTF)(char *, char *, ...) = lsprintf;
int (*VPRINTF)(char *, ...) = lprintf;
int (*BUGPRINTF)(char *, ...) = lprintf;
#endif
/* function pointers needed by portability modules */
void *(*VMALLOC)() = malloc;
void *(*VCALLOC)() = calloc;
void (*VFREE)() = free;
void (*VEXIT)() = exit;
int (*VREAD)() = read;
int (*VOPEN)() = open;
int (*VCLOSE)() = close;
int (*VLSEEK)() = lseek;
int (*VWRITE)() = write;
void (*VABORT)() = abort;
int (*VPRINTCHAR)() = lprintchar;
void (*VPRINTSTR)() = lprintstr;
void (*VCRASH)(char* fmt, ...) = lcrash;
void (*VBITBLT)();
int (*VSTAT)() = lnulfunc;
/* function pointers used internally */
int (*CFINIT)();
void (*CFEXIT)();
int (*COSINIT)();
void (*THREADER)();
void (*THREAD)();
int *VINHIBIT_THREADER;
/* cff function pointers used but not available until cff is loaded */